<?php

namespace addons\fastflow;

use app\common\library\Menu;
use think\Addons;

/**
 * 插件
 */
class Fastflow extends Addons
{

    /**
     * 插件安装方法
     * @return bool
     */
    public function install()
    {
        $menu = [
            [
                'name'    => 'fastflow',
                'title'   => '工作流系统',
                'icon'    => 'fa fa-list-alt',
                'sublist' => [
					[
						"name"    => 'fastflow/billlist',
						"title"   => "单据列表",
						"icon"    => 'fa fa-list-alt',
						"weigh"   => 0,
						"ismenu"  => 0,
						"status"  => 'hidden',
						"sublist" => [
                            [
                                "name"    => 'fastflow/billlist/index',
                                "title"   => "查看",
                                "icon"    => 'fa fa-user-circle-o',
                                "weigh"   => -1,
                            ]
                        ]
					],
                    [
                        "name"    => 'fastflow/bill',
                        "title"   => "单据列表",
                        "icon"    => 'fa fa-list-alt',
                        "weigh"   => -1,
                        "sublist" => [
                            [
                                "name"    => 'fastflow/bill/fastflow_demo_leave',
                                "title"   => "请假审批(演示)",
                                "icon"    => 'fa fa-user-circle-o',
                                "weigh"   => -1,
                                "sublist" => [
                                    ["name" => 'fastflow/bill/fastflow_demo_leave/index', "title" => '查看'],
                                    ["name" => 'fastflow/bill/fastflow_demo_leave/add', "title" => '添加'],
                                    ["name" => 'fastflow/bill/fastflow_demo_leave/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/bill/fastflow_demo_leave/del', "title" => '删除'],
                                    ["name" => 'fastflow/bill/fastflow_demo_leave/multi', "title" => '批量更新'],
                                ]
                            ]
                        ]
                    ],
                    [
                        "name"    => 'fastflow/signature',
                        "title"   => "电子签章",
                        "icon"    => 'fa fa-file-word-o',
                        "weigh"   => -2,
                        "sublist" => [
                            ["name" => 'fastflow/signature/initiate', "title" => "发起签章"],
                            ["name" => 'fastflow/signature/stamp', "title" => "进行签章"],
                            [
                                "name"   => 'fastflow/signature/canstamp',
                                "title"  => "待签章",
                                "icon"   => 'fa fa-file-pdf-o',
                                "weigh"  => -1,
                                "ismenu" => 1
                            ],
                            [
                                "name"   => 'fastflow/signature/initiated',
                                "title"  => "我发起的",
                                "icon"   => 'fa fa-folder-open',
                                "weigh"  => -2,
                                "ismenu" => 1
                            ],
                            [
                                "name"   => 'fastflow/signature/stamped',
                                "title"  => "我已签的",
                                "icon"   => 'fa fa-pencil-square',
                                "weigh"  => -3,
                                "ismenu" => 1
                            ],
							[
                                "name"   => 'fastflow/signature/check',
                                "title"  => "表单验证",
                                "icon"   => 'fa fa-check-circle',
                                "weigh"  => -4,
                                "ismenu" => 1
                            ],
                        ]
                    ],
                    [
                        "name"    => 'fastflow/flow',
                        "title"   => "系统管理",
                        "icon"    => 'fa fa-list',
                        "weigh"   => -3,
                        "sublist" => [
							[
                                "name"    => 'fastflow/flow/config',
                                "title"   => "系统配置",
                                "icon"    => 'fa fa-gear',
                                "weigh"   => -1,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/config/index', "title" => '系统配置页'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/bill',
                                "title"   => "单据管理",
                                "icon"    => 'fa fa-clipboard',
                                "weigh"   => -2,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/bill/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/flow/bill/add', "title" => '新增单据'],
                                    ["name" => 'fastflow/flow/bill/fromtable', "title" => '从数据表创建单据'],
                                    ["name" => 'fastflow/flow/bill/del', "title" => '删除单据'],
                                    ["name" => 'fastflow/flow/bill/index', "title" => '查看'],
                                    ["name" => 'fastflow/flow/bill/multi', "title" => '批量更新'],
                                    ["name" => 'fastflow/flow/bill/auth', "title" => '权限配置'],
                                    ["name" => 'fastflow/flow/ebill/add', "title" => '添加电子单据'],
                                    ["name" => 'fastflow/flow/ebill/index', "title" => '电子表单管理'],
                                    ["name" => 'fastflow/flow/ebill/edit', "title" => '编辑电子表单'],
                                    ["name" => 'fastflow/flow/ebill/del', "title" => '删除电子表单'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/stamp/index',
                                "title"   => "签章管理",
                                "icon"    => 'fa fa-bullseye',
                                "weigh"   => -3,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/stamp/add', "title" => '添加签章'],
                                    ["name" => 'fastflow/flow/stamp/edit', "title" => '编辑签章'],
                                    ["name" => 'fastflow/flow/stamp/del', "title" => '删除签章'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/flow',
                                "title"   => "流程管理",
                                "icon"    => 'fa fa-list-alt',
                                "weigh"   => -4,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/flow/index', "title" => '查看'],
                                    ["name" => 'fastflow/flow/flow/add', "title" => '添加'],
                                    ["name" => 'fastflow/flow/flow/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/flow/flow/del', "title" => '删除'],
                                    ["name" => 'fastflow/flow/flow/multi', "title" => '批量更新'],
                                    ["name" => 'fastflow/flow/flow/designer', "title" => '流程设计'],
                                    ["name" => 'fastflow/flow/flow/detail', "title" => '详情'],
                                    ["name" => 'fastflow/flow/flow/exportWord', "title" => '保存为Word'],
                                    ["name" => 'fastflow/flow/flow/auth', "title" => '权限配置'],
                                    ["name" => 'fastflow/flow/flow/savegraph', "title" => '保存流程图'],
                                    ["name" => 'fastflow/flow/flow/import', "title" => '导入'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/process',
                                "title"   => "流程监控",
                                "icon"    => 'fa fa-tv',
                                "weigh"   => -5,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/process/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/flow/process/add', "title" => '添加'],
                                    ["name" => 'fastflow/flow/process/del', "title" => '删除'],
                                    ["name" => 'fastflow/flow/process/termination', "title" => '强制终止'],
                                    ["name" => 'fastflow/flow/process/index', "title" => '查看'],
                                    ["name" => 'fastflow/flow/process/multi', "title" => '批量更新'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/agency',
                                "title"   => "委托代理",
                                "icon"    => 'fa fa-handshake-o',
                                "weigh"   => -6,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/agency/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/flow/agency/add', "title" => '添加'],
                                    ["name" => 'fastflow/flow/agency/del', "title" => '删除'],
                                    ["name" => 'fastflow/flow/agency/index', "title" => '查看'],
                                    ["name" => 'fastflow/flow/agency/multi', "title" => '批量更新'],
                                ]
                            ],
                            [
                                "name"    => 'fastflow/flow/message',
                                "title"   => "消息配置",
                                "icon"    => 'fa fa-envelope-o',
                                "weigh"   => -7,
                                "sublist" => [
                                    ["name" => 'fastflow/flow/message/edit', "title" => '编辑'],
                                    ["name" => 'fastflow/flow/message/add', "title" => '添加'],
                                    ["name" => 'fastflow/flow/message/del', "title" => '删除'],
                                    ["name" => 'fastflow/flow/message/index', "title" => '查看'],
                                    ["name" => 'fastflow/flow/message/multi', "title" => '批量更新'],
                                    ["name" => 'fastflow/flow/message/import', "title" => '导入'],
                                    ["name" => 'fastflow/flow/message/test', "title" => '消息测试'],
                                ]
                            ],
                        ]
                    ],
                    [
                        "name"    => 'fastflow/carbon',
                        "title"   => "我的抄送",
                        "icon"    => 'fa fa-paper-plane',
                        "weigh"   => -4,
                        "sublist" => [
                            ["name" => 'fastflow/carbon/index', "title" => '查看'],
                            ["name" => 'fastflow/carbon/del', "title" => '删除'],
                            ["name" => 'fastflow/carbon/multi', "title" => '批量更新'],
                            ["name" => 'fastflow/carbon/detail', "title" => '详情'],
                            ["name" => 'fastflow/carbon/exportWord', "title" => '保存为Word'],
                        ]
                    ],
                ],

            ],
        ];
        Menu::create($menu);
        return true;
    }

    /**
     * 插件卸载方法
     * @return bool
     */
    public function uninstall()
    {
        Menu::delete("fastflow");
        return true;
    }

    /**
     * 插件启用方法
     * @return bool
     */
    public function enable()
    {
        Menu::enable("fastflow");
        return true;
    }

    /**
     * 插件禁用方法
     * @return bool
     */
    public function disable()
    {
        Menu::disable("fastflow");
        return true;
    }

    /**
     * 应用初始化
     */
    public function appInit()
    {
        \think\Loader::addNamespace('fastflow', ADDON_PATH . 'fastflow' . DS . 'library' . DS . 'fastflow' . DS);
        if (request()->isCli()) {
            \think\Console::addDefaultCommands([
                'addons\fastflow\command\Crud',
                'addons\fastflow\command\Menu',
            ]);
        }
    }

}
